package com.mpp.admin.controller;


import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mapp
 * @des
 * @date 2019/2/13
 */
@Controller
public class LoginController {

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    /**
     * 登录失败操作（默认使用的是shiro自带的表单FormAuthenticationFilter 拦截器，已进行过登录，
     * 当然也可以自定义拦截器）
     * @param request
     * @return
     */
    @PostMapping("/login")
    public String loginPost(HttpServletRequest request) {
        String exception = (String) request.getAttribute("shiroLoginFailure");
        if (!StringUtils.isEmpty(exception)) {
            request.setAttribute("error", "用户名或密码错误");
        }
        return "login";
    }

    @GetMapping("/index")
    public String index() {
        return "index";
    }

    @GetMapping("/403")
    public String go403() {
        return "403";
    }
}
